﻿using System;
using System.Collections.Generic;
using System.Text;
using Abp.Dependency;
using Abp.Events.Bus.Entities;
using Abp.Events.Bus.Handlers;
using Abp.RemoteEventBus;
using Abp.Runtime.Caching;
using FwProject.Comm;
using FwProject.Core.FactoryInfo;

namespace FwProject.Application.EventHandle
{
    public class FactoryNameInfoHandle: IEventHandler<EntityChangedEventData<FactoryNameInfo>>, ITransientDependency
    {
        public readonly ICacheManager _catchmanager;
        public IRemoteEventBus remoteEventBus { get; set; }//缓存对象
        public FactoryNameInfoHandle(ICacheManager catchmanager)
        {
            _catchmanager = catchmanager;
            remoteEventBus = NullRemoteEventBus.Instance;
        }
        /// <summary>
        /// 删除缓存
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public void HandleEvent(EntityChangedEventData<FactoryNameInfo> eventData)
        {
            ICache cache = _catchmanager.GetCache(nameof(FactoryNameInfo));
            cache.Remove("list");

            var catcheventDate = new RemoteEventData(RemoteTypeHelp.TypeModelCatch)
            {
                Data = { [RemoteTypeHelp.Model] = nameof(FactoryNameInfo) }
            };
            remoteEventBus.Publish(RemoteTypeHelp.TopicSystemCatch, catcheventDate);

        }
    }
}